<template>
  <iframe :src="pdf" style="width: 100%;height: 100%; border: 0"></iframe>
</template>
<script setup>
  import { ref } from 'vue'
  import app from '@/app'

  const pdf = ref('')
  const emit = defineEmits(['load', 'over'])

  // 共用PDF对象
  let pdfdoc

  // 生成PDF
  const create = (view) => {
    emit('load')
    pdfdoc = app.pdf.load(view)

    // 显示预览
    pdfdoc.data().then(res => {
      pdf.value = res
      emit('over')
    })
  }

  // 下载 
  const down = (name) => {
    pdfdoc.down(name)
  }

  defineExpose({ create, down })
</script>